/*
 * Copyright 2018-2019 KunMinX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain menu_text_color copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.gzwanchuang.xhgj.bridge.data.repository;

import androidx.lifecycle.MutableLiveData;

import com.gzwanchuang.xhgj.bridge.data.bean.ServiceBean;
import com.gzwanchuang.xhgj.help.ImageHelper;
import com.gzwanchuang.xhgj.help.UserHelper;
import com.gzwanchuang.xhgj.net.NetworkManager;
import com.gzwanchuang.xhgj.net.interfaces.OnRequestCallBack;
import com.gzwanchuang.xhgj.proto.Area;
import com.gzwanchuang.xhgj.proto.Bank;
import com.gzwanchuang.xhgj.proto.Connect;
import com.gzwanchuang.xhgj.proto.Index;
import com.gzwanchuang.xhgj.proto.Information;
import com.gzwanchuang.xhgj.proto.LoginOuterClass;
import com.gzwanchuang.xhgj.proto.MemberOuterClass;
import com.gzwanchuang.xhgj.proto.Memberfeedback;
import com.gzwanchuang.xhgj.proto.Merchantservice;
import com.gzwanchuang.xhgj.proto.Statistics;
import com.google.protobuf.InvalidProtocolBufferException;

import java.util.List;

/**
 * Create by KunMinX at 19/10/29
 */
public class HttpRequestManager implements IRemoteRequest {

    private static HttpRequestManager sRequestManager = new HttpRequestManager();

    private HttpRequestManager() {
    }

    public static HttpRequestManager getInstance() {
        return sRequestManager;
    }



    // 登录方法
    @Override
    public void login(MutableLiveData<LoginOuterClass.Login> liveData, MutableLiveData<String> errorString, String userName, String password) {
        LoginOuterClass.Login.Builder builder = LoginOuterClass.Login.newBuilder();
        builder.setUsername(userName);
        builder.setPassword(password);
        builder.setClient("android");
        LoginOuterClass.Login data = builder.build();
        NetworkManager.INSTANCE.post(Apis.login, data.toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                LoginOuterClass.Login resp = LoginOuterClass.Login.parseFrom(bytes);
                liveData.setValue(resp);
            }

            @Override
            public void onError(int code, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 忘记密码
    @Override
    public void forgetPassword(MutableLiveData<String> resultString, MutableLiveData<String> errorString, String phone, String password, String code) {
        Connect.sms_register.Builder builder = Connect.sms_register.newBuilder();
        builder.setPhone(phone);
        builder.setPassword(password);
        builder.setCaptcha(code);
        builder.setRePassword(password);
        builder.setClient("android");
        Connect.sms_register data = builder.build();
        NetworkManager.INSTANCE.post(Apis.forgetPassword, data.toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) {
            }

            @Override
            public void onError(int code, String errorMessage) {
                if (code == 200) {
                    resultString.setValue(errorMessage);
                } else {
                    errorString.setValue(errorMessage);
                }
            }
        });
    }

    // 获取验证码   1 为注册, 3为找回登录密码, 5银行卡手机验证
    @Override
    public void getCode(MutableLiveData<String> resultString, MutableLiveData<String> errorString, String phone, String type) {
        Connect.captcha.Builder builder = Connect.captcha.newBuilder();
        builder.setPhone(phone);
        builder.setType(type);
        Connect.captcha data = builder.build();
        NetworkManager.INSTANCE.post(Apis.getMobileCode, data.toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) {
            }

            @Override
            public void onError(int code, String errorMessage) {
                if (code == 200) {
                    resultString.setValue(errorMessage);
                } else {
                    errorString.setValue(errorMessage);
                }
            }
        });
    }

    // 注册
    @Override
    public void register(MutableLiveData<String> resultString, MutableLiveData<String> errorString, String phone, String password, String code,String sncode) {
        Connect.sms_register.Builder builder = Connect.sms_register.newBuilder();
        builder.setPhone(phone);
        builder.setPassword(password);
        builder.setCaptcha(code);
        builder.setRePassword(password);
        builder.setSnCode(sncode);
        builder.setClient("android");
        Connect.sms_register data = builder.build();
        NetworkManager.INSTANCE.post(Apis.register, data.toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) {
            }

            @Override
            public void onError(int code, String errorMessage) {
                if (code == 200) {
                    resultString.setValue(errorMessage);
                } else {
                    errorString.setValue(errorMessage);
                }
            }
        });
    }

    // 上传图片
    @Override
    public void upLoadImage(MutableLiveData<String> resultString, MutableLiveData<String> errorString, String path) {
        ImageHelper.upLoadImage(path, new ImageHelper.OnUpLoadImageCallBack() {
            @Override
            public void onSuccess(String images) throws InvalidProtocolBufferException {
                String[] temp = images.split(",");
                byte[] bytes = new byte[temp.length];
                for (int i = 0; i < temp.length; i++) {
                    bytes[i] = (byte) Integer.parseInt(temp[i]);
                }
                resultString.setValue(MemberOuterClass.img_upload.parseFrom(bytes).getImg());
            }

            @Override
            public void onFail(String error) {
                errorString.setValue(error);
            }
        });
    }

    // 第一步 实名认证
    @Override
    public void intent(MutableLiveData<String> resultString, MutableLiveData<String> errorString, String uploadPath, String uploadPathTwo, String uploadPaththree, String name, String qrcode) {
        Merchantservice.authenticate.Builder builders = Merchantservice.authenticate.newBuilder();
        builders.setName(name).setIdCard(qrcode)
                .setIdCardFront(uploadPath).setIdCardBack(uploadPathTwo).setPersonIdCard(uploadPaththree);
        NetworkManager.INSTANCE.post(Apis.authenticate, builders.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) {

            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                if (errorCode == 200) {
                    resultString.setValue(errorMessage);
                } else {
                    errorString.setValue(errorMessage);
                }
            }
        });
    }


    // 第二步人脸识别
    @Override
    public void face_check(MutableLiveData<String> resultString, MutableLiveData<String> errorString, String idCardFront) {
        Merchantservice.authenticate.Builder builders = Merchantservice.authenticate.newBuilder();
        builders.setIdCardFront(idCardFront);
        NetworkManager.INSTANCE.post(Apis.face_check, builders.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) {

            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                if (errorCode == 200) {
                    resultString.setValue(errorMessage);
                } else {
                    errorString.setValue(errorMessage);
                }
            }
        });
    }


    // 第三步 获取MCC
    @Override
    public void getmcc(MutableLiveData<List<Merchantservice.mcc>> mccArray, MutableLiveData<String> errorString, String searchName) {
        Merchantservice.getmcc.Builder builder = Merchantservice.getmcc.newBuilder();
        builder.setName(searchName);
        NetworkManager.INSTANCE.post(Apis.getmcc, builder.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                Merchantservice.getmcc resp = Merchantservice.getmcc.parseFrom(bytes);
                mccArray.setValue(resp.getArrayList());
            }

            @Override
            public void onError(int code, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 第三部 获取地区列表
    @Override
    public void area_list(MutableLiveData<List<Area.area>> areas, MutableLiveData<String> errorString, String area_id) {
        Area.area_list.Builder builder = Area.area_list.newBuilder();
        builder.setAreaId(area_id);
        NetworkManager.INSTANCE.post(Apis.get_areas_list, builder.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                Area.area_list resp = Area.area_list.parseFrom(bytes);
                areas.setValue(resp.getAreaListList());
            }

            @Override
            public void onError(int code, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 第三部 MCC认证
    @Override
    public void modify_mcc(MutableLiveData<String> resultString, MutableLiveData<String> errorString, String name, String mccCode,
                           String provinceCode, String cityCode, String areaCode, String mccDetailAdree) {
        Merchantservice.modify_mcc.Builder builder = Merchantservice.modify_mcc.newBuilder();
        builder.setProvinceCode(provinceCode).setCityCode(cityCode).setAreaCode(areaCode)
                .setMcc(mccCode).setMccName(name).setReceiveAddress(mccDetailAdree);
        NetworkManager.INSTANCE.post(Apis.modify_mcc, builder.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) {

            }

            @Override
            public void onError(int code, String errorMessage) {
                if (code == 200) {
                    resultString.setValue(errorMessage);
                } else {
                    errorString.setValue(errorMessage);
                }
            }
        });
    }

    // 第四部 银行卡认证
    @Override
    public void audit(MutableLiveData<String> resultString, MutableLiveData<String> errorString,
                      String uploadPath, String uploadPathTwo, String uploadPathThree, String name,
                      String bankCardCode, String phone,
                      String code) {
//        Merchantservice.audit.Builder builder = Merchantservice.audit.newBuilder();
//        builder.setBankCardFront(uploadPath).setBankCardBack(uploadPathTwo).setPersonBankCard(uploadPathThree)
//                .setPhoneNo(phone).setName(name).setCardNo(bankCardCode).setSmsCode(code);
//        NetworkManager.INSTANCE.post(Apis.audit, builder.build().toByteArray(), new OnRequestCallBack() {
//            @Override
//            public void onOk(byte[] bytes) {
//
//            }
//
//            @Override
//            public void onError(int code, String errorMessage) {
//                if (code == 200) {
//                    resultString.setValue(errorMessage);
//                } else {
//                    errorString.setValue(errorMessage);
//                }
//            }
//        });
    }

    // 获取支持银行列表
    @Override
    public void get_support(MutableLiveData<List<Bank.bank>> banks, MutableLiveData<String> errorString, String type, String form) {
        Bank.get_bank.Builder builder = Bank.get_bank.newBuilder();
        builder.setType(type).setForm(form);
        NetworkManager.INSTANCE.post(Apis.get_support, builder.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                banks.setValue(Bank.get_bank.parseFrom(bytes).getListList());
            }

            @Override
            public void onError(int code, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 第五步 信用卡认证 发送验证码
    @Override
    public void credit_send(MutableLiveData<Merchantservice.credit_card> credit_card, MutableLiveData<String> errorString, String name, String card,
                            String valid_time, String cvv, String mobile) {
        Merchantservice.credit_card.Builder builders = Merchantservice.credit_card.newBuilder();
        builders.setCard(card).setValidTime(valid_time).setCvv(cvv).setMobile(mobile);
        NetworkManager.INSTANCE.post(Apis.credit_send, builders.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) throws InvalidProtocolBufferException {
                Merchantservice.credit_card rep = Merchantservice.credit_card.parseFrom(response);
                credit_card.setValue(rep);
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 第五步 信用卡认证
    @Override
    public void creditCard(MutableLiveData<String> resultString, MutableLiveData<String> errorString,
                           String name, String card, String valid_time, String cvv, String mobile, String orderId, String captcha) {
        Merchantservice.credit_card.Builder builders = Merchantservice.credit_card.newBuilder();
        builders.setCard(card).setValidTime(valid_time).setCvv(cvv).setMobile(mobile).setOrderId(orderId).setCaptcha(captcha);
        NetworkManager.INSTANCE.post(Apis.credit_card, builders.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) {

            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                if (errorCode == 200) {
                    resultString.setValue(errorMessage);
                } else {
                    errorString.setValue(errorMessage);
                }
            }
        });
    }

    // 第六步 绑定机器
    @Override
    public void bind(MutableLiveData<String> resultString, MutableLiveData<String> errorString, String snCode) {
        Merchantservice.bind.Builder builders = Merchantservice.bind.newBuilder();
        builders.setSn(snCode);
        NetworkManager.INSTANCE.post(Apis.bind, builders.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) {
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                if (errorCode == 200) {
                    resultString.setValue(errorMessage);
                } else {
                    errorString.setValue(errorMessage);
                }
            }
        });
    }

    // 获取个人信息
    @Override
    public void get_member_info(MutableLiveData<MemberOuterClass.Member> member, MutableLiveData<String> errorString) {
        NetworkManager.INSTANCE.post(Apis.get_member_info, new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) throws InvalidProtocolBufferException {
                member.setValue(MemberOuterClass.Member.parseFrom(response));
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 发送验证码
    @Override
    public void send_code(MutableLiveData<String> codeString, MutableLiveData<String> errorString,
                          String mPhone, String bankCardCode) {
        Merchantservice.send_code.Builder builders = Merchantservice.send_code.newBuilder();
        builders.setCardNo(bankCardCode).setPhoneNo(mPhone);
        NetworkManager.INSTANCE.post(Apis.send_code, builders.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) {
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                if (errorCode == 200) {
                    codeString.setValue(errorMessage);
                } else {
                    errorString.setValue(errorMessage);
                }
            }
        });
    }

    // 首页Banner的数据
    @Override
    public void getBanner(MutableLiveData<Index.get_show_list> showList, MutableLiveData<String> errorString) {

        NetworkManager.INSTANCE.post(Apis.get_banner, new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                Index.get_show_list data = Index.get_show_list.parseFrom(bytes);
                showList.setValue(data);
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });

    }

    // 获取首页交易数据
    @Override
    public void get_trading_list(MutableLiveData<List<Statistics.trading>> showList, MutableLiveData<String> errorString, int page,
                                 String typeNumber, String statusNumber,String month, String dayFirst, String dayEnd) {
        Statistics.get_trading_list.Builder builders = Statistics.get_trading_list.newBuilder();
        builders.setType(typeNumber).setMonth(month).setStartDay(dayFirst).setEndDay(dayEnd).setStatus(statusNumber);
        NetworkManager.INSTANCE.post(Apis.get_trading_list, builders.build().toByteArray(), page, new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                Statistics.get_trading_list data = Statistics.get_trading_list.parseFrom(bytes);
                showList.setValue(data.getListList());
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 获取结算卡（只有一张)）
    @Override
    public void get_bank(MutableLiveData<Bank.bank> bank, MutableLiveData<String> errorString, String type, String form) {
        Bank.get_bank.Builder builders = Bank.get_bank.newBuilder();
        builders.setType(type).setForm(form);
        NetworkManager.INSTANCE.post(Apis.get_bank, builders.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                Bank.get_bank get_bank = Bank.get_bank.parseFrom(bytes);
                bank.setValue(get_bank.getListList().get(0));
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 获取信用卡
    @Override
    public void get_bank_list(MutableLiveData<List<Bank.bank>> bankList, MutableLiveData<String> errorString, String type, String form) {
        Bank.get_bank.Builder builders = Bank.get_bank.newBuilder();
        builders.setType(type).setForm(form);
        NetworkManager.INSTANCE.post(Apis.get_bank, builders.build().toByteArray(), new OnRequestCallBack() {
                @Override
                public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                    Bank.get_bank get_bank = Bank.get_bank.parseFrom(bytes);
                    bankList.setValue(get_bank.getListList());
                }

                @Override
                public void onError(int errorCode, String errorMessage) {
                    errorString.setValue(errorMessage);
                }
            });
    }

    // 获取账单列表
    @Override
    public void get_trading_detail(MutableLiveData<Statistics.trading> tradingDetail, MutableLiveData<String>
            errorString, String id, String time) {
        Statistics.trading.Builder builders = Statistics.trading.newBuilder();
        builders.setId(id).setTime(time);
        NetworkManager.INSTANCE.post(Apis.get_trading_detail, builders.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                Statistics.trading rep = Statistics.trading.parseFrom(bytes);
                tradingDetail.setValue(rep);
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 解绑信用卡
    @Override
    public void unbind_card(MutableLiveData<String> resultString, MutableLiveData<String> errorString, String id) {
        Bank.bank.Builder builders = Bank.bank.newBuilder();
        builders.setId(id);
        NetworkManager.INSTANCE.post(Apis.unbind_card, builders.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) { }

            @Override
            public void onError(int code, String errorMessage) {
                if (code == 200) {
                    resultString.setValue(errorMessage);
                } else {
                    errorString.setValue(errorMessage);
                }
            }
        });
    }

    // 获取绑定机具列表
    @Override
    public void get_sn(MutableLiveData<Merchantservice.bind> bind, MutableLiveData<String> errorString) {
        NetworkManager.INSTANCE.post(Apis.get_sn, new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                bind.setValue(Merchantservice.bind.parseFrom(bytes));
            }

            @Override
            public void onError(int code, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 首页关于XXX列表
    @Override
    public void informationIndex(MutableLiveData<List<Information.DetailInfo>> detailInfos, MutableLiveData<String> errorString) {
        NetworkManager.INSTANCE.post(Apis.information_index, new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                detailInfos.setValue(Information.InformationList.parseFrom(bytes).getIndexListList());
            }

            @Override
            public void onError(int code, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 统计线性图表
    @Override
    public void get_trend(MutableLiveData<Statistics.get_statistics> statists, MutableLiveData<String> errorString, String time) {
        Statistics.get_statistics.Builder builders = Statistics.get_statistics.newBuilder();
        builders.setMonth(time);
        NetworkManager.INSTANCE.post(Apis.get_trend, builders.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                statists.setValue(Statistics.get_statistics.parseFrom(bytes));
            }

            @Override
            public void onError(int code, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 统计刷卡数据与底部百分比
    @Override
    public void get_statistics(MutableLiveData<Statistics.get_statistics> statists, MutableLiveData<String> errorString, String time) {
        Statistics.get_statistics.Builder builders = Statistics.get_statistics.newBuilder();
        builders.setMonth(time);
        NetworkManager.INSTANCE.post(Apis.get_statistics, builders.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                statists.setValue(Statistics.get_statistics.parseFrom(bytes));
            }

            @Override
            public void onError(int code, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 消息列表
    @Override
    public void system_log(MutableLiveData<List<MemberOuterClass.SysteLog.SystemLogList>> system_logs, MutableLiveData<String> errorString, int page) {
        NetworkManager.INSTANCE.post(Apis.system_log, page, new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) throws InvalidProtocolBufferException {
                MemberOuterClass.SysteLog systeLog = MemberOuterClass.SysteLog.parseFrom(bytes);
                system_logs.setValue(systeLog.getSystemLogListList());
            }

            @Override
            public void onError(int code, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 意见反馈
    @Override
    public void feedback_add(MutableLiveData<String> resultString, MutableLiveData<String> errorString, String feedback) {
        Memberfeedback.FeedbackAdd.Builder builders = Memberfeedback.FeedbackAdd.newBuilder();
        builders.setFeedback(feedback);
        NetworkManager.INSTANCE.post(Apis.feedback_add, builders.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] bytes) {

            }

            @Override
            public void onError(int code, String errorMessage) {
                if (code == 200) {
                    resultString.setValue(errorMessage);
                } else {
                    errorString.setValue(errorMessage);
                }
            }
        });
    }

    // 获取客服信息
    @Override
    public void get_kfu_info(MutableLiveData<Index.get_kfu_info> kfuBean, MutableLiveData<String> errorString) {
        NetworkManager.INSTANCE.post(Apis.get_kfu_info, new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) throws InvalidProtocolBufferException {
                Index.get_kfu_info kefu_message = Index.get_kfu_info.parseFrom(response);
                kfuBean.setValue(kefu_message);
                ServiceBean serviceBean = new ServiceBean();
                serviceBean.setMember_id(kefu_message.getMemberId());
                serviceBean.setMember_name(kefu_message.getMemberName());
                serviceBean.setMember_mobile(kefu_message.getMemberMobile());
                serviceBean.setMember_avatar(kefu_message.getMemberAvatar());
                serviceBean.setChat_id(kefu_message.getChatId());
                serviceBean.setChat_pwd(kefu_message.getChatPwd());
                UserHelper.saveKeFuUserInfo(serviceBean);
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }

    // 创建订单 （用于刷卡页面）
    @Override
    public void created_order(MutableLiveData<MemberOuterClass.created_order> order, MutableLiveData<String> errorString) {
        NetworkManager.INSTANCE.post(Apis.created_order, new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) throws InvalidProtocolBufferException {
                MemberOuterClass.created_order rep =MemberOuterClass.created_order.parseFrom(response);
                order.setValue(rep);
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                errorString.setValue(errorMessage);
            }
        });
    }
}
























